package main

import (
	"fmt"
	"time"
)

//func main() {
//	var a [10]int
//	fmt.Println("Running in", runtime.Version())
//	for i := 0; i < 10; i++ {
//		go func(i int) {
//			for {
//				a[i]++
//			}
//		}(i)
//	}
//	time.Sleep(time.Millisecond)
//	fmt.Println(a)
//
//}
func main() {
	//abc := make(chan int, 1000)
	//for i := 0; i < 10; i++ {
	//	abc <- i
	//}
	//go func() {
	//	for a := range abc {
	//		fmt.Println("a: ", a)
	//	}
	//}()
	//close(abc)
	//fmt.Println("close")
	//time.Sleep(time.Second * 100)

	//以下代码可能会输出：
	//ok
	//close
	//panic: send on closed channel
	ch := make(chan int, 1000)
	go func() {
		for i := 0; i < 10; i++ {
			ch <- i
		}
	}()
	go func() {
		for {
			a, ok := <-ch
			if !ok {
				fmt.Println("close")
				return
			}
			fmt.Println("a: ", a)
		}
	}()
	close(ch)
	fmt.Println("ok")
	time.Sleep(time.Second * 100)

}
